<template>
  <div class="warp">
    <div class="cantianer">
      <div class="middle">
        <div class="header">
          全部

          <button class="header-btn">热门</button>
        </div>
        <ul class="distList" @click="toSongListDetail">
          <li
            class="dist"
            v-for="(item, index) in list"
            :data-lid="item.id"
            :key="index"
          >
            <a :title="item.name">
              <div class="imgCont">
                <img
                  :src="item.coverImgUrl"
                  :alt="item.name"
                  class="imageslist"
                  :data-lid="item.id"
                />
                <div class="imgTitle">
                  <div>
                    <span class="iconfont icon-icon_headset"></span
                    ><i>{{ format(item.playCount) }}</i>
                  </div>
                  <span class="iconfont icon-bofang"></span>
                </div>
              </div>
              <a :title="item.name" class="mark">{{ item.name }}</a>
              <p class="dist-mask">
                <span>by</span>
                <a :title="item.creator.nickname">{{
                  item.creator.nickname
                }}</a>
                <img
                  class="iconImg"
                  :src="item.creator.avatarDetail?.identityIconUrl"
                />
              </p>
            </a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { reqGetList, reqTagsApi } from '@/api/recommend'
//

import { songListItem } from '@/api/model/songList'
import { useRouter } from 'vue-router'

const router = useRouter()
let list: any = ref([])

interface type {
  limit: number | string
  before: null | string | number
}
let data: type = { limit: 50, before: null }
const total = ref(0)
function format(count: number) {
  let playCountStr

  if (count.toString().length > 5) {
    playCountStr = Math.floor(count / 10000) + '万'
    return playCountStr
  } else {
    return (playCountStr = count)
  }
}
function toSongListDetail(e: any) {
  jump(e.target.dataset.lid)
}
//limit: 取出歌单数量 , 默认为 50
function jump(id: number) {
  router.push('/detail/songlist?songListId=' + id)
}
const getListMusic = async () => {
  const result = await reqGetList(data)
  list.value = result.playlists
}

onMounted(getListMusic)
onMounted(async () => {
  const resultList = await reqTagsApi()
  console.log(resultList)
})
</script>

<style scoped>
.dist-mask a {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.iconImg {
  width: 14px;
  height: 14px;
  display: inline-block;
  margin-left: 5px;
}
.warp {
  width: 100%;
  height: 100%;
  background-color: #f5f5f5;
}
.cantianer {
  margin: 0 auto;
  width: 980px;
  height: 100%;
  background-color: #ffffff;
}
.middle {
  padding: 40px;
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #c20c0c;
  color: #c20c0c;
  font-size: 24px;
  height: 40px;
  font-weight: normal;
}
.header-btn:hover {
  text-decoration: underline;
}
.header-btn {
  color: #ffffff;
  background-color: #c20c0c;
  border: none;
  width: 46px;
  height: 29px;
  background-position: 0 0;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
}
.mark {
  display: inline-block;
  width: 140px;
  height: 20px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  font-size: 14px;
  margin: 8px 0 3px 0;
}
.dist {
  width: 140px;
  height: 188px;
  cursor: pointer;
  margin: 0 50px 30px 0;
  display: inline-block;
}
ul {
  margin-top: 30px;
}
.dist-mask {
  width: 100%;
  height: 18px;
  display: flex;
  font-size: 12px;
}
.dist-mask a:hover {
  text-decoration: underline;
}
.dist-mask a {
  color: #333;
  margin: 0 3px;
}
.dist-mask span {
  color: #999999;
}

.dist:nth-child(5n) {
  margin-right: 0;
}
.dist:first-child {
  margin-left: 0;
}
.imgCont {
  position: relative;
}
.imgTitle div span {
  font-size: 18px;
}
.imgTitle {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 27px;
  width: 100%;
  color: #ccc;
  background-color: rgba(75, 71, 69, 0.6);
  border-top: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.imgTitle div {
  display: flex;
  align-items: center;
}
.imgTitle div i {
  font-size: 12px;
}
.imgTitle span {
  margin: 0 8px;
  font-size: 18px;
}
.imageslist {
  width: 140xp;
  height: 140px;
}
</style>
